package com.example.recyclerviewlearn;

import android.content.Context;
import android.graphics.Color;
import android.media.Image;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class AnimationLinearLayoutManager extends LinearLayoutManager {
    private static final String TAG = "AnimationLinearLayoutMa";

    private Context mContext;

    public AnimationLinearLayoutManager(Context context) {
        super(context);
        mContext = context;
    }

    public AnimationLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
        super(context, orientation, reverseLayout);
        mContext = context;
    }

    public AnimationLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mContext = context;
    }


    @Override
    public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
        super.onLayoutChildren(recycler, state);
    }

    private boolean mInitialized = false;

    @Override
    public void onLayoutCompleted(RecyclerView.State state) {
        super.onLayoutCompleted(state);
//        if (mInitialized) {
//            return;
//        }
//        mInitialized = true;
//        Log.i(TAG, "onLayoutCompleted: ");
//        Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.scaleanim_scale_1);
//        animation.setAnimationListener(new Animation.AnimationListener() {
//            @Override
//            public void onAnimationStart(Animation animation) {
//                Log.i(TAG, "onAnimationStart: animation");
//            }
//
//            @Override
//            public void onAnimationEnd(Animation animation) {
//
//            }
//
//            @Override
//            public void onAnimationRepeat(Animation animation) {
//
//            }
//        });
//        ViewGroup view = (ViewGroup) getChildAt(2);
//        ImageView imageView = new ImageView(mContext);
//        imageView.setBackgroundResource(R.drawable.ic_launcher_background);
//        view.addView(imageView);
//        View view3 = getChildAt(3);
//        view.bringToFront();
//        view.setBackgroundColor(Color.RED);
//        Log.i(TAG, "onLayoutCompleted: startAnimation(animation)");
//        view.startAnimation(animation);
//        Animation animation1 = AnimationUtils.loadAnimation(mContext, R.anim.translateanim);
//        view3.startAnimation(animation1);
//        Log.i(TAG, "onLayoutCompleted: end");
    }
}
